var t = require('../@babel/runtime/helpers/regeneratorRuntime.js'),
  a = require('../@babel/runtime/helpers/asyncToGenerator.js'),
  e = require('D28B336470B67DCFB4ED5B639AB21B27.js'),
  r = getApp();
module.exports = Behavior({
  properties: {},
  data: {},
  pageLifetimes: { show: function () {} },
  created: function () {
    var t = (2 * wx.getSystemInfoSync().screenWidth) / 750;
    this.data.pure_rpx = t;
  },
  attached: function () {},
  ready: function () {},
  methods: {
    drawGoods: function (t, a) {
      for (
        var r = this.data.pure_tabOne,
          o = this.data.pure_rpx,
          h = r.list.slice(0, 6),
          l = 0;
        l < h.length;
        l++
      ) {
        var i = h[l],
          n = 40 + (l % 3) * 230,
          f = 480 + 330 * Math.floor(l / 3),
          s = a[i.id + '_thumb'];
        e.canvas_roundRect(
          t,
          Math.floor(n * o),
          Math.floor(f * o),
          Math.floor(210 * o),
          Math.floor(210 * o),
          Math.floor(8 * o),
          '#ccc',
        ),
          t.clip(),
          t.drawImage(
            s.path,
            0,
            0,
            s.width,
            s.height,
            Math.floor(n * o),
            Math.floor(f * o),
            Math.floor(210 * o),
            Math.floor(210 * o),
          ),
          t.restore(),
          t.save();
      }
      (t.fillStyle = '#fb6a2b'), (t.font = '500 26px DIN');
      for (var d = 0; d < h.length; d++) {
        var c = h[d],
          u = 40 + (d % 3) * 230,
          p = 690 + 330 * Math.floor(d / 3),
          M = Number(c.shop_price),
          g = Math.floor(t.measureText('¥ '.concat(M)).width + 20);
        t.beginPath(),
          t.moveTo(u * o, (p - 4) * o),
          t.arc(
            (u + 4) * o,
            (p - 4) * o,
            4 * o,
            1 * Math.PI,
            0.5 * Math.PI,
            !0,
          ),
          t.lineTo((u + g) * o, p * o),
          t.arc(
            (u + g) * o,
            (p - 19) * o,
            19 * o,
            0.5 * Math.PI,
            1.5 * Math.PI,
            !0,
          ),
          t.lineTo((u + 19) * o, (p - 38) * o),
          t.arc(
            (u + 19) * o,
            (p - 19) * o,
            19 * o,
            1.5 * Math.PI,
            1 * Math.PI,
            !0,
          ),
          t.fill();
      }
      t.save(),
        (t.font = '500 '.concat(Math.floor(26 * o), 'px DIN')),
        (t.fillStyle = '#fff');
      for (var w = 0; w < h.length; w++) {
        var v = h[w],
          m = 44 + (w % 3) * 230,
          x = 690 + 330 * Math.floor(w / 3),
          I = Number(v.shop_price);
        t.fillText('¥ ' + I, (m + 13) * o, (x - 8) * o);
      }
      t.save(), t.beginPath(), (t.fillStyle = '#202124');
      for (var _ = 0; _ < h.length; _++) {
        var b = h[_],
          T = 40 + (_ % 3) * 230,
          P = 690 + 330 * Math.floor(_ / 3);
        e.canvas_dealWords({
          ctx: t,
          fontSize: 26 * o,
          lineHeight: 38 * o,
          word: b.title,
          maxWidth: parseInt(210 * o),
          x: parseInt(T * o),
          y: parseInt(P * o),
          maxLine: 2,
          outType: ' ',
        });
      }
    },
    handName: function (t) {
      for (
        var a = this.data.pure_nickname,
          e = t.measureText('的微折购小店').width,
          r = a,
          o = 0;
        o < a.length;
        o++
      ) {
        if (t.measureText(a.substring(0, o + 1)).width + e >= 286)
          return {
            text: (r = a.substring(0, o) + '...'),
            wasCrop: !0,
            width: 286,
          };
      }
      return { text: r, wasCrop: !1, width: e + t.measureText(a).width };
    },
    __draw: function (o) {
      var h = this;
      return a(
        t().mark(function a() {
          var l, i, n, f, s, d, c, u, p, M, g, w;
          return t().wrap(function (t) {
            for (;;)
              switch ((t.prev = t.next)) {
                case 0:
                  return (
                    (l = h),
                    (i = h.data),
                    (n = i.pure_tabOne),
                    i.pure_nickname,
                    (f = i.handle_height),
                    (s = o.box_bg),
                    (d = o.xuxian),
                    (c = o.QRimg),
                    (u = o.logo),
                    (p = o.userBg),
                    (M = o.thumb),
                    (g = h.data.pure_rpx),
                    (w = wx.createCanvasContext('shareAd', h)),
                    750,
                    1616,
                    t.abrupt(
                      'return',
                      new Promise(function (t, a) {
                        (w.fillStyle = n.background_color || 'white'),
                          w.fillRect(
                            0,
                            0,
                            parseInt(750 * g),
                            parseInt(1616 * g),
                          ),
                          w.save(),
                          w.drawImage(
                            s.path,
                            0,
                            0,
                            s.width,
                            s.height,
                            0,
                            0,
                            Math.floor(750 * g),
                            Math.floor(460 * g),
                          ),
                          e.canvas_roundRect(
                            w,
                            Math.floor(20 * g),
                            Math.floor(460 * g),
                            Math.floor(710 * g),
                            Math.floor((1069 + f) * g),
                            Math.floor(12 * g),
                            '#fff',
                          ),
                          w.drawImage(
                            d.path,
                            0,
                            0,
                            d.width,
                            d.height,
                            Math.floor(38 * g),
                            Math.floor((1130 + f) * g),
                            Math.floor(680 * g),
                            Math.floor(3 * g),
                          ),
                          w.save(),
                          (w.font = '500 24px DIN');
                        var i = h.handName(w);
                        w.beginPath(),
                          i.wasCrop
                            ? w.drawImage(
                                p.path,
                                0,
                                0,
                                p.width,
                                p.height,
                                Math.floor(22 * g),
                                Math.floor(36 * g),
                                Math.floor(362 * g),
                                Math.floor(56 * g),
                              )
                            : (e.canvas_roundRect(
                                w,
                                Math.floor(22 * g),
                                Math.floor(36 * g),
                                Math.floor((76 + i.width) * g),
                                Math.floor(56 * g),
                                Math.floor(28 * g),
                                !1,
                              ),
                              w.clip(),
                              w.drawImage(
                                p.path,
                                0,
                                0,
                                p.width,
                                p.height,
                                Math.floor(22 * g),
                                Math.floor(36 * g),
                                Math.floor(362 * g),
                                Math.floor(56 * g),
                              ),
                              w.restore()),
                          w.save(),
                          w.beginPath(),
                          w.arc(50 * g, 64 * g, 24 * g, 0, 2 * Math.PI),
                          w.clip(),
                          w.drawImage(
                            M.path,
                            0,
                            0,
                            M.width,
                            M.height,
                            Math.floor(26 * g),
                            Math.floor(40 * g),
                            Math.floor(48 * g),
                            Math.floor(48 * g),
                          ),
                          w.restore(),
                          (w.font = '500 24px DIN'),
                          (w.fillStyle = '#fff'),
                          (w.font = '500 '.concat(
                            Math.floor(24 * g),
                            'px DIN',
                          )),
                          w.fillText(i.text + '的微折购小店', 81 * g, 72 * g),
                          w.save(),
                          h.drawGoods(w, o),
                          w.beginPath(),
                          w.drawImage(
                            c.path,
                            0,
                            0,
                            c.width,
                            c.height,
                            239 * g,
                            (1133 + f) * g,
                            270 * g,
                            270 * g,
                          ),
                          w.save();
                        var v = '长按图片识别二维码';
                        if (
                          M.pure_src.includes(r.CONFIG.DEFAULT_AVATAR) ||
                          c.pure_src.includes('default')
                        ) {
                          v = M.pure_src.includes(r.CONFIG.DEFAULT_AVATAR)
                            ? '请登录后重新获取'
                            : '请重新获取分享图片';
                          var m = l.data.reloadBtnMap;
                          (m[n.share_id] = !0), l.setData({ reloadBtnMap: m });
                        } else {
                          var x = l.data.reloadBtnMap;
                          (x[n.share_id] = !1),
                            l.setData({ reloadBtnMap: x }),
                            w.beginPath(),
                            w.arc(
                              375 * g,
                              (1267 + f) * g,
                              57 * g,
                              0,
                              2 * Math.PI,
                            ),
                            w.clip(),
                            w.drawImage(
                              M.path,
                              0,
                              0,
                              M.width,
                              M.height,
                              Math.floor(318 * g),
                              Math.floor((1210 + f) * g),
                              Math.floor(114 * g),
                              Math.floor(114 * g),
                            ),
                            w.restore();
                        }
                        if (
                          ((w.font = '500 '.concat(
                            Math.floor(24 * g),
                            'px DIN',
                          )),
                          (w.fillStyle = '#666666'),
                          w.fillText(v, 270 * g, (1432 + f) * g),
                          n.end_at)
                        ) {
                          var I = n.end_at + ' 专场结束';
                          w.font = '500 24px DIN';
                          var _ = w.measureText(I).width + 44,
                            b = (750 - _) / 2;
                          e.canvas_roundRect(
                            w,
                            Math.floor(b * g),
                            Math.floor((1458 + f) * g),
                            Math.floor(_ * g),
                            Math.floor(44 * g),
                            Math.floor(22 * g),
                            '#FFFBEC',
                            '#D89557',
                          ),
                            w.beginPath(),
                            (w.font = '500 '.concat(
                              Math.floor(24 * g),
                              'px DIN',
                            )),
                            (w.fillStyle = '#FF8600'),
                            w.fillText(
                              I,
                              Math.floor((b + 21) * g),
                              Math.floor((1488 + f) * g),
                            ),
                            w.save();
                        }
                        w.beginPath(),
                          w.drawImage(
                            u.path,
                            0,
                            0,
                            u.width,
                            u.height,
                            306 * g,
                            (1550 + f) * g,
                            144 * g,
                            46 * g,
                          ),
                          w.save(),
                          w.beginPath(),
                          w.save(),
                          w.draw(!1, function (a) {
                            'drawCanvas:ok' === a.errMsg
                              ? setTimeout(function () {
                                  wx.canvasToTempFilePath(
                                    {
                                      destWidth: 2250,
                                      destHeight: 3 * (1616 + f),
                                      quality: 0.78,
                                      fileType: 'jpg',
                                      canvasId: 'shareAd',
                                      success: function (a) {
                                        t(a.tempFilePath);
                                      },
                                    },
                                    l,
                                  );
                                }, 100)
                              : (console.error('WTF draw callback!!'),
                                setTimeout(function () {
                                  wx.canvasToTempFilePath(
                                    {
                                      destWidth: 2250,
                                      destHeight: 4848,
                                      quality: 0.78,
                                      fileType: 'jpg',
                                      canvasId: 'shareAd',
                                      success: function (a) {
                                        t(a.tempFilePath);
                                      },
                                    },
                                    l,
                                  );
                                }, 300));
                          });
                      }),
                    )
                  );
                case 8:
                case 'end':
                  return t.stop();
              }
          }, a);
        }),
      )();
    },
  },
});
